package com.anzia.demo08;

import java.math.BigDecimal;

/**
 *@ClassName BigDecimal_Demo
 *@Description
 *@Author Anzia.
 *@Date 2021/4/11 19:04
 *@Version 1.0
 **/
public class BigDecimal_Demo {
    public static void main(String[] args) {
        double d1 = 1.0;
        double d2 = 0.9;
        System.out.println(d1-d2);

        double result = (1.4-0.5)/0.9;
        System.out.println(result);
        //BigDecimal，大的浮点数精确计算
        BigDecimal bd1 = new BigDecimal("1.0");
        BigDecimal bd2 = new BigDecimal("0.9");
        //减法
        BigDecimal subtract = bd1.subtract(bd2);
        System.out.println(subtract);
        //加法
        BigDecimal add = bd1.add(bd2);
        System.out.println(add);
        //乘法
        BigDecimal multiply = bd1.multiply(bd2);
        System.out.println(multiply);
        //除法
        System.out.println(new BigDecimal("1.4")
                .subtract(new BigDecimal("0.5"))
                .divide(new BigDecimal("0.9")));

    }
}
